//
//  main.m
//  第一个OC类-方法3
//
//  Created by 许文娟 on 2024/1/10.
//

#import <Foundation/Foundation.h>

//颜色枚举
typedef enum
{
    kIcolorBlack,
    kIcolorWhite,
    kIcolorRed
} IColor;
//1、类的声明（属性+行为）
@interface Iphone:NSObject
//属性
{
    //默认OC对象中的属性不能直接访问
    
    @public  //属性公开
    float _model; //型号
    int _cpu;
    double _size; //尺寸
//    int _color; //颜色
//    enum IColor _color;
    IColor _color;
    
}
//行为
-(void)about;
//-(char *) loadMessage;
//-(int) call: (int) number;
//-(int)sendMessageWithNumber: (int)number antContent:(char *)content;
////计算器
//-(int)sumWithValue1:(int)value1 andValue2:(int)value2;
////类方法
//+(int)sumWithValue1:(int)value1 andValue2:(int)value2;

//-(NSString *)colorWithNumber:(IColor)number;
+(NSString *)colorWithNumber:(IColor)number;
@end

//2、编写类的实现
@implementation Iphone
//行为的实现
-(void)about
{
    //对象方法使用
//    Iphone *p = [Iphone new];
//    NSString *name =[p colorWithNumber:_color];
    NSString *name =[Iphone colorWithNumber:_color];
NSLog(@"size=%f,color=%@,model=%f,cpu=%i",_size,name,_model,_cpu);
}

//工具方法，根据传入的整数返回对应的字符串
//-(NSString *)colorWithNumber:(IColor)number
+(NSString *)colorWithNumber:(IColor)number
{
    NSString *name;
    switch (number){
        case 0:
            name = @"黑色";
            break;
        case 1:
            name = @"白色";
            break;
        case 2:
            name = @"红色";
            break;
        default:
            name = @"华强北";
            break;
    }
    return name;
}
@end

int main(int argc, const char * argv[]) {
    
    //创建对象
    Iphone *p = [Iphone new];
    
    //3、修改对象的属性
    p->_size = 3.5;
    p->_color = kIcolorRed;
    p->_model = 4;
    p->_cpu = 1;
    [p about];
    return 0;
}
